package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.appcompat.widget.AppCompatImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.GoodsListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.databinding.ItemGoodsBinding

/**
 * @author: hxw
 * @date  : 2023/2/2
 * @desc  :
 */
class MallProductAdapter(data: ArrayList<GoodsListResponse.ListBean>) :
    BaseQuickAdapter<GoodsListResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_goods, data) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: DataBindBaseViewHolder, item: GoodsListResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemGoodsBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

//        binding.root.product_item_price.text = "¥ ${item.minPrice.toString().trim()}"
        SettingUtil.setPrice(item.minPrice.toString().trim(), binding.productItemPrice, 50, context.resources.getColor(R.color.color_red))
        val imageGoodsIcon = holder.getView<AppCompatImageView>(R.id.riv_item_icon)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.goodImg, imageGoodsIcon, 10, R.drawable.shop_product_def)
        when (item.brandType) {
            1 -> {
                binding.tvBrandType.text = context.getString(R.string.homegrown)//"国产"
                binding.tvBrandType.setBackgroundResource(R.drawable.brand_type2_tv)
            }

            2 -> {
                binding.tvBrandType.text = context.getString(R.string.import_goods)//"进口"
                binding.tvBrandType.setBackgroundResource(R.drawable.brand_type1_tv)
            }
        }
    }
}